﻿<?php

//申明常用变量
$list1='<list>';
$list2='</list>';

//把id传递过来的参数抓取到$id变量中
$id= $_GET['id']; 

//判断id参数是否为空
if($id=="")
        {
        echo "没有参数啊，骚年。";
        }
else
        {
        //将URL源码放入$code变量中
        $code="http://pgmsvr.tv189.cn/program/getVideoPlayInfo?pid=".$id;
        $code = file_get_contents($code);

        //取影片标题
        $tezheng = '/tt><!\[CDATA\[(.*?)\]\]/i';
        preg_match_all($tezheng, $code, $jieguo);
        foreach ($jieguo[1] as $linshi => $title)
        $title=$title;

        //判断输入是否错误
        if($title=="")
                {
                //输出获取出错的XML文件
                echo $list1."\n";
                echo '<m type="2" src="亲，该片暂时无法播放。" label="亲，该片暂时无法播放。" />'."\n";
                echo '<m type="2" src="亲，请联系OW反馈错误。" label="亲，请联系OW反馈错误。" />'."\n";
                echo $list2;
                }

        //如果取到了标题就开始取清晰度
        elseif (preg_match ("/1080p/i", $code))
                {
                $bytes450tezheng = '/sz=(.*?)450P/i';
                preg_match_all($bytes450tezheng, $code, $bytes450jieguo);
                foreach ($bytes450jieguo[1] as $bytes450linshi => $bytes450)        
                $bytes450tezheng = '/"(.*?)"/i';
                preg_match_all($bytes450tezheng, $bytes450, $bytes450jieguo);
                foreach ($bytes450jieguo[1] as $bytes450linshi => $bytes450)        

                $duration450tezheng = '/450P" tm="(.*?)" vid=/i';
                preg_match_all($duration450tezheng, $code, $duration450jieguo);
                foreach ($duration450jieguo[1] as $duration450linshi => $duration450)

                $flv450tezheng = '/"><!\[CDATA\[(.*?)450p-0000.flv/i';
                preg_match_all($flv450tezheng, $code, $flv450jieguo);
                foreach ($flv450jieguo[1] as $flv450linshi => $flv450)

                $bytes720tezheng = '/sz=(.*?)720P/i';
                preg_match_all($bytes720tezheng, $code, $bytes720jieguo);
                foreach ($bytes720jieguo[1] as $bytes720linshi => $bytes720)        
                $bytes720tezheng = '/"(.*?)"/i';
                preg_match_all($bytes720tezheng, $bytes720, $bytes720jieguo);
                foreach ($bytes720jieguo[1] as $bytes720linshi => $bytes720)        

                $duration720tezheng = '/720P" tm="(.*?)" vid=/i';
                preg_match_all($duration720tezheng, $code, $duration720jieguo);
                foreach ($duration720jieguo[1] as $duration720linshi => $duration720)

                $flv720tezheng = '/"><!\[CDATA\[(.*?)720p-0000.flv/i';
                preg_match_all($flv720tezheng, $code, $flv720jieguo);
                foreach ($flv720jieguo[1] as $flv720linshi => $flv720)

                $bytes1080tezheng = '/sz=(.*?)1080P/i';
                preg_match_all($bytes1080tezheng, $code, $bytes1080jieguo);
                foreach ($bytes1080jieguo[1] as $bytes1080linshi => $bytes1080)        
                $bytes1080tezheng = '/"(.*?)"/i';
                preg_match_all($bytes1080tezheng, $bytes1080, $bytes1080jieguo);
                foreach ($bytes1080jieguo[1] as $bytes1080linshi => $bytes1080)        

                $duration1080tezheng = '/1080P" tm="(.*?)" vid=/i';
                preg_match_all($duration1080tezheng, $code, $duration1080jieguo);
                foreach ($duration1080jieguo[1] as $duration1080linshi => $duration1080)

                $flv1080tezheng = '/"><!\[CDATA\[(.*?)1080p-0000.flv/i';
                preg_match_all($flv1080tezheng, $code, $flv1080jieguo);
                foreach ($flv1080jieguo[1] as $flv1080linshi => $flv1080)

                //输出1080P的XML文件
                echo $list1."\n";
                echo '<m type="2" src="'.$flv720.'720p-0000.flv?start={start_bytes}" duration="'.$duration720.'" bytes="'.$bytes720.'" label="'.$title.' 高清[2M]" />'."\n";
                echo '<m type="2" src="'.$flv450.'450p-0000.flv?start={start_bytes}" duration="'.$duration450.'" bytes="'.$bytes450.'" label="'.$title.' 标清[1M]" />'."\n";
                echo '<m type="2" src="'.$flv1080.'1080p-0000.flv?start={start_bytes}" duration="'.$duration1080.'" bytes="'.$bytes1080.'" label="'.$title.' 超清[4M]" />'."\n";
                echo $list2;
                }
        elseif  (preg_match ("/720p/i", $code)) 
                {
                $bytes450tezheng = '/sz=(.*?)450P/i';
                preg_match_all($bytes450tezheng, $code, $bytes450jieguo);
                foreach ($bytes450jieguo[1] as $bytes450linshi => $bytes450)        
                $bytes450tezheng = '/"(.*?)"/i';
                preg_match_all($bytes450tezheng, $bytes450, $bytes450jieguo);
                foreach ($bytes450jieguo[1] as $bytes450linshi => $bytes450)        
                $duration450tezheng = '/450P" tm="(.*?)" vid=/i';
                preg_match_all($duration450tezheng, $code, $duration450jieguo);
                foreach ($duration450jieguo[1] as $duration450linshi => $duration450)
                $flv450tezheng = '/"><!\[CDATA\[(.*?)450p-0000.flv/i';
                preg_match_all($flv450tezheng, $code, $flv450jieguo);
                foreach ($flv450jieguo[1] as $flv450linshi => $flv450)
                $bytes720tezheng = '/sz=(.*?)720P/i';
                preg_match_all($bytes720tezheng, $code, $bytes720jieguo);
                foreach ($bytes720jieguo[1] as $bytes720linshi => $bytes720)        
                $bytes720tezheng = '/"(.*?)"/i';
                preg_match_all($bytes720tezheng, $bytes720, $bytes720jieguo);
                foreach ($bytes720jieguo[1] as $bytes720linshi => $bytes720)        
                $duration720tezheng = '/720P" tm="(.*?)" vid=/i';
                preg_match_all($duration720tezheng, $code, $duration720jieguo);
                foreach ($duration720jieguo[1] as $duration720linshi => $duration720)

                $flv720tezheng = '/"><!\[CDATA\[(.*?)720p-0000.flv/i';
                preg_match_all($flv720tezheng, $code, $flv720jieguo);
                foreach ($flv720jieguo[1] as $flv720linshi => $flv720)

                //输出720P的XML文件
                echo $list1."\n";
                echo '<m type="2" src="'.$flv720.'720p-0000.flv?start={start_bytes}" duration="'.$duration720.'" bytes="'.$bytes720.'"        label="'.$title.' 高清[2M]" />'."\n";
                echo '<m type="2" src="'.$flv450.'450p-0000.flv?start={start_bytes}" duration="'.$duration450.'" bytes="'.$bytes450.'"        label="'.$title.' 标清[1M]" />'."\n";
                echo $list2;
                } 
                elseif (preg_match ("/450p/i", $code)) 
                {
                $bytes450tezheng = '/sz=(.*?)450P/i';
                preg_match_all($bytes450tezheng, $code, $bytes450jieguo);
                foreach ($bytes450jieguo[1] as $bytes450linshi => $bytes450)        
                $bytes450tezheng = '/"(.*?)"/i';
                preg_match_all($bytes450tezheng, $bytes450, $bytes450jieguo);
                foreach ($bytes450jieguo[1] as $bytes450linshi => $bytes450)        

                $duration450tezheng = '/450P" tm="(.*?)" vid=/i';
                preg_match_all($duration450tezheng, $code, $duration450jieguo);
                foreach ($duration450jieguo[1] as $duration450linshi => $duration450)

                $flv450tezheng = '/"><!\[CDATA\[(.*?)450p-0000.flv/i';
                preg_match_all($flv450tezheng, $code, $flv450jieguo);
                foreach ($flv450jieguo[1] as $flv450linshi => $flv450)

                //输出450P的XML文件
                echo $list1."\n";
                echo '<m type="2" src="'.$flv450.'450p-0000.flv?start={start_bytes}" duration="'.$duration450.'" bytes="'.$bytes450.'" label="'.$title.' 标清[1M]" />'."\n";
                echo $list2;
                } 
                }
?>